package cn.zzf.algs.note.base.sort;

import cn.zzf.algs.note.base.util.SortUtil;

/**
 * @author GaoFeng2017
 * @date 2020/6/16 15:19
 */
public class SelectionSort implements Sort {

    @Override
    public void sort(Comparable[] elements) {
        // 插入排序，先选出0 - index范围内最小的，然后将该最小的元素的下标与element[index] 交换
        int currentMinIndex;
        for (int i = 0; i < elements.length - 1; i++) {
            currentMinIndex = i;
            for (int j = i + 1; j < elements.length; j++) {
                if (SortUtil.less(elements[j], elements[currentMinIndex])) {
                    currentMinIndex = j;
                }
            }
            SortUtil.exchange(elements, i, currentMinIndex);
        }
        // 测试排序
    }

}
